
package com.shamar.blog.enums;

import org.apache.commons.lang3.ArrayUtils;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author zhy
 * @date 2019-12-29
 * @descrption 支付方式枚举类
 */
public enum PayType {

    /**
     * 后期优化，将渠道查询结果更新处理 迁移至各渠道查询实现类中
     * @Link com.wanwu.channel.biz.impl.PayBizImpl.handlePayQuery
     *      todo 注意后续每接一个渠道 或者 加渠道中得支付方式，都得在上面方法中添加对应得 PayType
     *       支付宝处理  ALIPAY
     *       微信处理   WECHAT
     *       通联处理   ALLIAN
     */
    WECHAT_APP(1, "微信app支付", "weixinGlobalStrategy","weChatDeclareCustoms"),
    WECHAT_MINI(2, "微信小程序", "weixinGlobalStrategy","weChatDeclareCustoms"),
    ALIPAY_APP(3, "支付宝手机APP支付", "alipayAppPayStrategy","aliDeclareCustomsImpl"),
    ALIPAY_HK_APP(4, "支付宝香港APP支付", "alipayAppHKStrategy","aliDeclareCustomsImpl"),
    ALLIAN_WECHAT_PAY(5, "通联微信APP支付", "tongLianPayStrategy","tlDeclareCustomsImpl"),
    ALLIAN_WECHAT_MINI_PAY(6, "通联微信小程序支付", "tongLianPayStrategy","tlDeclareCustomsImpl"),
    ALLIAN_ALI_PAY(7, "通联支付宝支付", "tongLianPayStrategy","tlDeclareCustomsImpl"),
    ALLIAN_CLEAR_PAY(8, "通联跨境清分支付", "allinClearStrategy","tlDeclareCustomsImpl"),
    WECHAT_H5(9, "微信H5支付", "weixinGlobalStrategy","weChatDeclareCustoms"),
    ALLIAN_H5(10, "通联H5支付", "tongLianH5PayStrategy","tlDeclareCustomsImpl"),
    ALIPAY_H5(11, "支付宝手机H5支付", "alipayAppPayStrategy","aliDeclareCustomsImpl"),

    ;


    private Integer value;
    private String desc;
    private String name;
    private String declare;

    PayType(Integer value, String desc) {
        this.value = value;
        this.desc = desc;

    }

    PayType(Integer value, String desc, String name) {
        this.value = value;
        this.desc = desc;
        this.name = name;
    }

    PayType(Integer value, String desc, String name, String declare) {
        this.value = value;
        this.desc = desc;
        this.name = name;
        this.declare = declare;
    }

    public static PayType getByCode(int value) {
        for (PayType type : PayType.values()) {
            if (type.value() == value) {
                return type;
            }
        }
        return null;
    }

    //通联渠道
    private static PayType[] allinpayList = {ALLIAN_WECHAT_PAY, ALLIAN_WECHAT_MINI_PAY, ALLIAN_ALI_PAY, ALLIAN_CLEAR_PAY, ALLIAN_H5};

    public static boolean isTonglian(Integer code) {
        PayType payType = getByCode(code);
        return ArrayUtils.contains(allinpayList, payType);
    }

    //支付宝渠道
    private static PayType[] aliPayList = {ALIPAY_APP, ALIPAY_HK_APP, ALIPAY_H5};

    public static boolean isAliPay(Integer code) {
        PayType payType = getByCode(code);
        return ArrayUtils.contains(aliPayList, payType);
    }

    //微信渠道
    private static PayType[] wechatList = {WECHAT_APP, WECHAT_MINI, WECHAT_H5};

    public static boolean isWechat(Integer code) {
        PayType payType = getByCode(code);
        return ArrayUtils.contains(wechatList, payType);
    }

    public boolean check(Integer value) {
        return this.value.intValue() == value.intValue();
    }

    public static Map<String, String> toMap() {
        Map<String, String> map = new LinkedHashMap<>();
        for (PayType value : values()) {
            map.put(String.valueOf(value.value), value.desc);
        }
        return map;
    }

    public Integer value() {
        return value;
    }

    public String desc() {
        return desc;
    }

    public Integer getValue() {
        return value;
    }

    public String getName() {return name;}

    public String getDeclare() {
        return declare;
    }
}
